
package com.hyst.config;

import javax.mail.Session;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.logging.log4j.web.Log4jServletContextListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.filter.DelegatingFilterProxy;

/***
 * 
 * @Description: web服务初始化类,用于取代web.xml的配置
 * @Date：2017年8月9日 @author： DongY
 * @version ：1.0 1.[2017年8月9日]CreatBy：dy
 */

public class WebInitializer implements WebApplicationInitializer {


	@Override
	public void onStartup(final ServletContext context) throws ServletException {
		// AnnotationConfigApplicationContext configApplicationContext = new
		// AnnotationConfigApplicationContext();
		// AnnotationConfigApplicationContext appContext = new
		// AnnotationConfigApplicationContext();
		// ServletRegistration.Dynamic dispatcher =
		// context.addServlet("dispatcher", new DispatcherServlet(appContext));
		// dispatcher.setLoadOnStartup(1);
		// dispatcher.addMapping("/");
		/***************************
		 * 配置log4j listener filter等
		 ***************************/
		System.out.println("============中文系统加载中...=============");
		context.addListener(Log4jServletContextListener.class);
//		context.addFilter("sessionFilter", SessionFilter.class).addMappingForUrlPatterns(null, true, "/*");

//		DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
//		filter.setServletContext(context);
//		filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
//		context.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, true, "/*");

		// javax.servlet.FilterRegistration.Dynamic filter=context.addFilter("",
		// Log4jServletFilter.class);
		// filter.addMappingForUrlPatterns(arg0, false, arg2);
		// DispatcherServlet
	}

}
